/**
 * @file       Button.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "Button.h"
#include "errorcode.h"
#include <cstdio>

namespace NS_LCD_AFW
{

CButton::CButton()
{
	this->setFocusable(true);
	this->setHightlightable(true);
}

CButton::~CButton()
{
}

void CButton::setText(std::string text)
{
	this->m_strText = text;
}

int CButton::onDraw(IDisplay *pDisplay)
{
	int iRet = ERR_SUCCESS;
	if (ERR_SUCCESS != (iRet = CFrame::onDraw(pDisplay)))
	{
		return iRet;
	}

	pDisplay->write(this->getPosition().getX(), this->getPosition().getY(),
			this->getRect().getWidth(), this->getRect().getHight(),
			m_strText.c_str());

	return iRet;
}



void CButton::onSetFocus()
{
	if (isHightlight())
	{
		onBtnClick();
	}
	else
	{
		this->setHightlight(true);
	}
}

void CButton::onLostFocus()
{
	this->setHightlight(false);
}

void CButton::onHightlight()
{
}

void CButton::onUnHightlight()
{
}


int CButton::onLeftKeyPress()
{
	return CFrame::onLeftKeyPress();
}

void CButton::onBtnClick()
{
}

int CButton::onRightKeyPress()
{
	onBtnClick();
	return ERR_SUCCESS;
}

int CButton::onEnterKeyPress()
{
	onBtnClick();
	return ERR_SUCCESS;
}

int CButton::onCreate()
{
	this->setText(this->getName());
	return CFrame::onCreate();
}

int CButton::onEscKeyPress()
{

	this->setFocus(false);
	this->setHightlight(false);
	return CFrame::onEscKeyPress();
}

int CButton::onUpKeyPress()
{

	this->setFocus(false);
	this->setHightlight(false);
	return CFrame::onUpKeyPress();
}

int CButton::onDownKeyPress()
{
	this->setFocus(false);
	this->setHightlight(false);
	return CFrame::onDownKeyPress();
}



} /* namespace NS_LCD_AFW */
